

pd<-paste(wd, "/Figures/Figures_Output/",sep="")


pdf(file=paste(pd,"beliefs_plot.pdf",sep=""), 6, 6)

beliefs<-read.csv(file="beliefs.csv")[,1:60]


par(mar=c(2,4,2,1))

plot(1951:2010, beliefs[1,],type="n",ylim=c(-.015,.026),axes=F,xlab="",ylab="", main="") 




grid()


polygon(c(2000,2010,2010,2000), c(-.02,-.02,.03,.03), col=rgb(.1,.1,.1,.1),border="NA")

quanti<-list()

for(i in 1:ncol(beliefs)){
  quanti[[i]]<-as.vector(quantile(beliefs[,i],c(.2,.3,.4,.5,.6,.7,.8) ) )
}

quanti<-do.call(rbind,quanti)



for(i in 1:ncol(quanti)){
  
  if(i ==1 | i ==6){col<-rgb(6/7-1/8,6/7-1/7,6/7,.7)}  
  
  if(i ==2 | i ==5){col<-rgb(5/7-1/8,5/7-1/7,5/7,.7)}   
  
  if(i ==3 | i ==4){col<-rgb(4/7-1/8,4/7-1/7,4/7,.7)}   
  
  
  try({
  polygon(c(1951:2010,2010:1951) ,c(quanti[,i], rev(quanti[,i+1]) ),col=col ,border="NA")
  })
  
  
}

axis(1);axis(2,seq(-.02,.03,by=.01),labels=seq(-2,3,by=1))

mtext(expression(bar(beta)^{D==1}-bar(beta)^{D==0}),2,line=2.5)

mtext("Worldwide Distribution of Beliefs",3,line=.5,font=2,cex=1.5)


#par(new=T)


#plot(res_nocv$years,res_nocv$pD,col=rgb(.1,.1,.1,.75),axes=F,type="l",lwd=2,xlab="",ylab="")

#mtext("% World Democracies",4,line=.75)


#axis(4,seq(.25,.6,by=.05),line=-1.25)



dev.off()



uncer<-read.csv("uncertainty_beliefs.csv")[,1:60]




pdf(file=paste(pd,"precision_plot.pdf",sep=""), 6, 6)



par(mar=c(2,4,2,1))

plot(1951:2010, uncer[1,],type="n",axes=F,xlab="",ylab="", main="",xlim=c(1951,2010),ylim=c(0.007,.06)) 




grid()


polygon(c(2000,2010,2010,2000), c(0,0,.06,.06), col=rgb(.1,.1,.1,.1),border="NA")

quanti<-list()

for(i in 1:ncol(uncer)){
  quanti[[i]]<-as.vector(quantile(uncer[,i],c(.2,.3,.4,.5,.6,.7,.8) ) )
}

quanti<-do.call(rbind,quanti)



for(i in 1:ncol(quanti)){
  
  if(i ==1 | i ==6){col<-rgb(6/7-1/8,6/7-1/7,6/7,.7)}  
  
  if(i ==2 | i ==5){col<-rgb(5/7-1/8,5/7-1/7,5/7,.7)}   
  
  if(i ==3 | i ==4){col<-rgb(4/7-1/8,4/7-1/7,4/7,.7)}   
  
  
  try({
  polygon(c(1951:2010,2010:1951) ,c(quanti[,i], rev(quanti[,i+1]) ),col=col ,border="NA")
  })
  
  
}

axis(1,seq(1950,2010,by=10));axis(2,seq(0,.06,by=.01),labels=seq(0,6,by=1))

abline(h=0.00,lty=2)


mtext("Distribution of Belief Uncertainty",3,cex=1.5,font=2)

mtext("Standard Deviation",2,line=2.5)



dev.off()



####################################################
